package com.liux.config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class MyLocaleResolver implements LocaleResolver {
    //解析需求
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {

        String language = httpServletRequest.getParameter("l");
        Locale locale = Locale.getDefault();//如果没有获取到就用默认的
        //如果请求链接不为空
        if(!StringUtils.isEmpty(language)){
            //分割请求链接不为空
            String[] split = language.split("_");
            //国家   地区
            locale = new Locale(split[0],split[1]);
        }
        return  locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }




}
